﻿CREATE TABLE [dbo].[Environment]
(
	[Id] [dbo].[Id] NOT NULL  IDENTITY(1000000000, 1), 
    [Name] [dbo].[Name] NOT NULL, 
    [Description] [dbo].[Description] NOT NULL , 
    [DatabaseType] [dbo].[EnumerationValue] NOT NULL DEFAULT 0, 
    [ServerName] [dbo].[Name] NOT NULL , 
    [DatabaseName] [dbo].[Name] NOT NULL, 
    [PoolingEnabled] BIT NOT NULL DEFAULT 1, 
    [PoolSizeMinimum] INT NOT NULL DEFAULT 1, 
    [PoolSizeMaximum] INT NOT NULL DEFAULT 10, 
    [TrustedConnection] BIT NOT NULL DEFAULT 1, 
    [UserName] [dbo].[Name] NULL, 
    [Password] VARCHAR(20) NULL, 
    [CustomAttributes] VARCHAR(99) NULL, 
    [CreateId] [dbo].[Name] NOT NULL, 
    [CreateDateTime] [dbo].[CreateModifiedDateTime] NOT NULL, 
    [ModifiedId] [dbo].[Name] NOT NULL, 
    [ModifiedDateTime] [dbo].[CreateModifiedDateTime] NOT NULL, 
    CONSTRAINT [PK_Environment] PRIMARY KEY ([Id]), 
    CONSTRAINT [CK_Environment_PoolSizeMinimum] CHECK ((PoolSizeMinimum > 0) AND (PoolSizeMinimum <= PoolSizeMaximum)),
	CONSTRAINT [CK_Environment_UserName] CHECK ((TrustedConnection = 0) OR ((TrustedConnection = 1) AND (UserName IS NOT NULL))), 
    CONSTRAINT [AK_Environment_Name] UNIQUE (Name)
	
)

GO
EXEC sp_addextendedproperty @name = N'MS_Description',
    @value = N'Custom Attributes for Connection String',
    @level0type = N'SCHEMA',
    @level0name = N'dbo',
    @level1type = N'TABLE',
    @level1name = N'Environment',
    @level2type = N'COLUMN',
    @level2name = N'CustomAttributes'